package com.techsen.tsweb.sys.domain;

import java.util.ArrayList;
import java.util.List;

import com.techsen.tsweb.core.domain.BaseEntity;
import com.techsen.tsweb.core.util.ValidUtil;

/**
 * 用户角色
 */
public class UserRole extends BaseEntity<UserRole> {

    private static final long serialVersionUID = 5054914837898444376L;

    /**
     * 用户ID
     */
    private String userId;
    
    /**
     * 角色ID
     */
    private String roleId;
    
    /**
     * 关联用户
     */
    private User user;
    
    /**
     * 关联角色
     */
    private Role role;
    
    /**
     * 获取用户集合
     */
    public static List<User> getUsersByUserRoles(List<UserRole> userroles) {
        List<User> users = new ArrayList<User>();
        if (ValidUtil.isValid(userroles)) {
            for (UserRole userrole : userroles) {
                users.add(userrole.getUser());
            }
        }
        return users;
    }
    
    /**
     * 获取用户ID集合
     */
    public static List<String> getUserIdsByUserRoles(List<UserRole> userroles) {
        List<String> userIds = new ArrayList<String>();
        if (ValidUtil.isValid(userroles)) {
            for (UserRole userrole : userroles) {
                userIds.add(userrole.getUserId());
            }
        }
        return userIds;
    }
    
    /**
     * 获取角色集合
     */
    public static List<Role> getRolesByUserRoles(List<UserRole> userroles) {
        List<Role> roles = new ArrayList<Role>();
        if (ValidUtil.isValid(userroles)) {
            for (UserRole userrole : userroles) {
                roles.add(userrole.getRole());
            }
        }
        return roles;
    }
    
    /**
     * 获取角色ID集合
     */
    public static List<String> getRoleIdsByUserRoles(List<UserRole> userroles) {
        List<String> roleIds = new ArrayList<String>();
        if (ValidUtil.isValid(userroles)) {
            for (UserRole userrole : userroles) {
                roleIds.add(userrole.getRoleId());
            }
        }
        return roleIds;
    }

    public String getUserId() {
        return userId;
    }

    public UserRole setUserId(String userId) {
        this.userId = userId;
        return this;
    }

    public String getRoleId() {
        return roleId;
    }

    public UserRole setRoleId(String roleId) {
        this.roleId = roleId;
        return this;
    }

    public User getUser() {
        return user;
    }

    public UserRole setUser(User user) {
        this.user = user;
        return this;
    }

    public Role getRole() {
        return role;
    }

    public UserRole setRole(Role role) {
        this.role = role;
        return this;
    }
    
}
